package com.onlineshop.highgee.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.onlineshop.highgee.dao.UserDao;
import com.onlineshop.highgee.dao.UserInfoDao;
import com.onlineshop.highgee.daoimpl.UserDaoImpl;
import com.onlineshop.highgee.daoimpl.UserDaoInfoImpl;
import com.onlineshop.highgee.entity.User;
import com.onlineshop.highgee.entity.UserInfo;



/**
 * Servlet implementation class UserInfoServlet
 */
@WebServlet("/UserInfoServlet")
public class UserInfoServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		try {
			System.out.println("UserServlet_doPost");
			// 鑾峰彇鏁版嵁锛堥〉闈級
			String user_name = request.getParameter("user_name");
			String password = request.getParameter("password");
			String sex = request.getParameter("sex");
			String email = request.getParameter("email");
			String phone = request.getParameter("phone");
			String address = request.getParameter("address");
			System.out.println("userServlet鐨勫唴瀹�"+"username:"+user_name+"password:"+password+"sex:"+sex+"email:"+email+"phone:"+phone+"address"+address);
			
			User user = new User();
			UserInfoDao userInfoDao=new UserDaoInfoImpl();
			UserDao userDao=new UserDaoImpl();
			UserInfo userInfo = new UserInfo();
			
			user.setUserName(user_name);
			user.setPassword(password);
			userInfo.setSex(sex);
			userInfo.setEmail(email);
			userInfo.setPhone(phone);
			userInfo.setAddress(address);
	
			userInfoDao.addUserInfo(userInfo);
			userDao.addUser(user);
		
			request.getRequestDispatcher("myaccount.jsp").forward(request, response);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
